package com.yiwenup.leetcode.site;

/**
 * https://leetcode-cn.com/problems/number-of-lines-to-write-string/
 */
public class No0806 {
    /**
     * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
     * 内存消耗：39.7 MB, 在所有 Java 提交中击败了10.18%
     */
    public int[] numberOfLines(int[] widths, String s) {
        int count = 1;
        int sum = 0;
        for (char c : s.toCharArray()) {
            int width = widths[c - 'a'];
            sum += width;
            if (sum > 100) {
                sum = width;
                count++;
            }
        }
        return new int[]{count, sum};
    }
}